package com.wuyoucar.controller;

import com.alibaba.fastjson.JSON;
import com.wuyoucar.common.ResultBean;
import com.wuyoucar.entity.TSafetype;
import com.wuyoucar.entity.TSafetypeitem;
import com.wuyoucar.service.TSafetypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
@RequestMapping("/tsafetype")
public class TSafetypeController {
    @Autowired
    private TSafetypeService tSafetypeService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    //查询所有险种信息
    @RequestMapping("/allrisks")
    public List<TSafetype> getAllTSafetype() {
        return tSafetypeService.getAllTSafetype();
    }

    //查询单个险种信息
    @RequestMapping("/getAllTSafetypeByid")
    public ResultBean getAllTSafetypeByid(Integer safetypeid) {
        ResultBean resultBean = new ResultBean();
        TSafetype allTSafetypeByid = tSafetypeService.getAllTSafetypeByid(safetypeid);
        if (allTSafetypeByid!=null){
            return new ResultBean(0,"查询成功",allTSafetypeByid);
        }else {
            return new ResultBean(1,"查询失败",null);
        }
    }

    //查询具体险种信息
    @RequestMapping("/AllSafeTypeItem")
    public List<TSafetypeitem> getAllTSafetypeitem(){
        return tSafetypeService.getAllTSafetypeitem();
    }


    @RequestMapping("/FillinVehicleiFnormation")
    public ResultBean FillinVehicleiFnormation(@RequestBody LinkedHashMap<String,String> mymap) {
        System.out.println(mymap);
        ResultBean resultBean = new ResultBean();

//        String jsonString = stringRedisTemplate.opsForValue().get(mymap.get("userid"));
//        HashMap<String,Object> map = JSON.parseObject(jsonString, HashMap.class);
//        System.out.println(map.get("forcity"));

        stringRedisTemplate.opsForValue().set(mymap.get("userid"), String.valueOf(mymap));
        resultBean.setCode(0);
        resultBean.setMsg("存储成功");
        return resultBean;
    }

}
